package com.example.demo.controller;
import com.example.demo.model.MessageInfo;
import com.example.demo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/message")
public class MessageController {
      @Autowired
      private MessageService messageService;
      @RequestMapping("/publish")
      public boolean publishMessage(MessageInfo messageInfo){
          System.out.println("=========");
          if(!StringUtils.hasLength(messageInfo.getFrom())||!StringUtils.hasLength(messageInfo.getTo())
             ||!StringUtils.hasLength(messageInfo.getMessage())){
              return false;
          }
          messageService.insertMessage(messageInfo);
          return  true;
      }
    @RequestMapping("/getList")
      public List<MessageInfo> getList(){
        System.out.println("=======================");
        return messageService.queryList();
      }
}